﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace Orange.Logistics.Models {
    [Table("Customers")]
    public class Customer : IValidatableObject {
        [Key]
        [Column("CustomerId")]
        [Required(ErrorMessage = "*")]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int CustomerId { get; set; }

        [Column("CustomerName"), MaxLength(50, ErrorMessage = "输入过长")]
        [Required(ErrorMessage = "*")]
        public string CustomerName { get; set; }

        [Column("ShortName"), MaxLength(20, ErrorMessage = "输入过长")]
        [Required(ErrorMessage = "*")]
        public string ShortName { get; set; }

        [Column("Address"), MaxLength(50, ErrorMessage = "输入过长")]
        public string Address { get; set; }

        [Column("MnCode"), MaxLength(50, ErrorMessage = "输入过长")]
        public string MnCode { get; set; }

        [Column("Phones"), MaxLength(25, ErrorMessage = "输入过长")]
        public string Phones { get; set; }

        [Column("Contract"), MaxLength(20, ErrorMessage = "输入过长")]
        public string Contract { get; set; }

        [Column("Status"), MaxLength(2, ErrorMessage = "输入过长")]
        public string Status { get; set; }

        [Column("PostCode"), MaxLength(10, ErrorMessage = "输入过长")]
        public string PostCode { get; set; }

        [Column("Remarks"), MaxLength(400, ErrorMessage = "输入过长")]
        [DataType(DataType.MultilineText)]
        public string Remarks { get; set; }

        [Column("Manualno"), MaxLength(20, ErrorMessage = "输入过长")]
        public string Manualno { get; set; }

        [Column("Fexs"), MaxLength(20, ErrorMessage = "输入过长")]
        public string Fexs { get; set; }

        [Column("Banks"), MaxLength(500, ErrorMessage = "输入过长")]
        public string Banks { get; set; }

        [Column("Account"), MaxLength(20, ErrorMessage = "输入过长")]
        public string Account { get; set; }

        [Column("Mobiles"), MaxLength(50, ErrorMessage = "输入过长")]
        public string Mobiles { get; set; }

        [Column("Emails"), MaxLength(255, ErrorMessage = "输入过长")]
        public string Emails { get; set; }

        [Column("Idcard"), MaxLength(20, ErrorMessage = "输入过长")]
        public string Idcard { get; set; }

        [Column("Trade")]
        public bool Trade { get; set; }

        [Column("Sign")]
        public bool Sign { get; set; }

        [Column("Isbatch")]
        public bool Isbatch { get; set; }

        [Column("LastExport")]
        public DateTime? LastExport { get; set; }

        [Column("Ispay")]
        public bool Ispay { get; set; }

        [Column("Modifyuser"), MaxLength(12, ErrorMessage = "输入过长")]
        public string Modifyuser { get; set; }

        [Column("Modifytime")]
        public DateTime Modifytime { get; set; }


        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
            if (string.IsNullOrEmpty(Status)) {
                yield return new ValidationResult("状态不能为空!");
            }
            if (string.IsNullOrEmpty(Modifyuser)) {
                yield return new ValidationResult("当前用户怎么空的?");
            }
        }
    }
}